/**
 * 构建表格头部
 * @param table_const
 * @param that :: 将this传入，用于调用国际化资源文件
 * @returns {Array}
 */
export function createTrHeader(table_const, that){
  var tHeader = [];
  for(var key in table_const) {
    if(table_const[key]['isShow'] && table_const[key]['showType']!=='operation') {
      let tempParams = table_const[key];
      tHeader.push(that.$t(tempParams['lang']));
    }
  }

  return tHeader;
}

/**
 * 构建数据列
 * @param table_const
 * @returns {Array}
 */
export function createShowColFilter(table_const){
  var filterVal = [];
  for(var key in table_const) {
    if(table_const[key]['isShow'] && table_const[key]['showType']!=='operation') {
      let tempParams = table_const[key];
      filterVal.push(tempParams['bindColName']);
    }
  }

  // console.log(filterVal);

  return filterVal;
}


/***
 * 按列格式化数据
 * @param filterVal
 * @param jsonData
 * @returns {*}
 */
export function formatJson(filterVal, jsonData, table_const, that) {
  return jsonData.map(v => filterVal.map(j => {
    let selectArray =  getSelectArray(table_const, j);

    if(selectArray) {
      for(var key in selectArray) {
        if(v[j] === selectArray[key]['value']) {
          return that.$t(selectArray[key]['label']);
        }
      }
    } else {
      return v[j]
    }
  }))
}

function getSelectArray(table_const, colName){
  for(var key in table_const) {
    if(table_const[key]['bindColName'] !== colName) continue;

    if(table_const[key]['isShow'] && table_const[key]['showType']!=='operation') {

      let tempParams = table_const[key];

      return tempParams['selectArray'];
    }
  }
}
